package io.xccit.aischool.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.models.auth.In;
import io.xccit.aischool.entity.Clazz;
import io.xccit.aischool.service.IClazzService;
import io.xccit.aischool.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.Nullable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author CH_ywx
 * @date 2023-06-06
 * @description
 */
@Api(tags = "班级接口")
@RestController
@RequestMapping("/sms/clazzController")
public class ClazzController {

    @Autowired
    private IClazzService clazzService;

    @ApiOperation("获取所有班级")
    @GetMapping("/getClazzs")
    public Result<List<Clazz>> getAllClazz(){
        return Result.ok(clazzService.getAllClazz());
    }

    @ApiOperation("添加/修改班级信息")
    @PostMapping("/saveOrUpdateClazz")
    public Result saveOrUpdate(@ApiParam("班级请求体") @RequestBody Clazz clazz){
        return Result.ok(clazzService.saveOrUpdate(clazz));
    }

    @ApiOperation("分页获取所有班级")
    @GetMapping("/getClazzsByOpr/{pageNo}/{pageSize}")
    public Result getClazzByOpr(@ApiParam("页数") @PathVariable Integer pageNo,
                              @ApiParam("每页总条数") @PathVariable Integer pageSize,
                                @ApiParam("年级名称,精确查询字段") @RequestParam @Nullable String gradeName,
                              @ApiParam("班级名称,模糊查询字段") @RequestParam @Nullable String clazzName){
        Page<Clazz> clazzPage = new Page<>(pageNo, pageSize);
        Page<Clazz> page = clazzService.getClazzByOpr(clazzPage,clazzName,gradeName);
        return Result.ok(page);
    }

    @ApiOperation("删除/批量删除班级")
    @DeleteMapping("/deleteClazz")
    public Result deleteClazzByIDs(@ApiParam("删除班级的id集合") @RequestBody List<Integer> ids){
        return Result.ok(clazzService.removeByIds(ids));
    }
}
